<template>
    <div class="articleDetail">
        <template v-if="article!=null">
            <el-card class="box-card">
                <div slot="header">
                    <div class="articleDetail-head">
                        <div class="head-other">
                            <i class="el-icon-edit" ></i><span>({{article.editTime | setTime}})</span>
                            |<i class="el-icon-folder"></i><a href="javascript:void(0);"
                                                              @click="toCategory(article.category.name)">
                            <span>{{article.category.cateName}}</span></a>
                            |<i class="el-icon-view"></i><span>{{article.pageView}}</span>
                            |<i class="el-icon-user"></i><span>{{article.user.zhName}}</span>
                        </div>
                        <div class="head-tags">
                            <el-tag style="cursor: pointer;margin-left: 5px" size="small" @click="toTag(tag.id)" effect="plain"
                                    v-for="(tag,index) in article.tags" :key="index">
                                {{tag.tagName}}
                            </el-tag>

                        </div>

                        <div class="head-title">
                            <h1>{{article.title}}</h1>
                        </div>
                    </div>

                </div>
                <div class="articleDetail-content">
                    <div id="write" v-html="article.htmlContent">
                    </div>
                    <div class="articleDetail-foot">
                        评论功能待完善
                    </div>
                </div>
            </el-card>



        </template>
    </div>
</template>

<script>
    import '../../assets/vue/css/fonts.css'
    export default {
        name: "index",
        data() {
            return {
                article: null,
            }
        },
        computed: {
            route: function () {
                return this.$route.params.code
            }
        },
        methods: {
            initArticle() {
                let code = this.$route.params.code;
                this.getRequest('/blog/article/getDetail?code=' + code).then(resp => {
                    if (resp) {
                        this.article = resp.obj;
                    }
                }).catch(res => {
                    console.log(res);
                });
            },
            index() {
                this.$router.push('/');
            },
            goOther(code) {
                this.$router.push({path: `/detail/${code}`});
            },
            toTag(tid) {
                console.log(tid)
            },
            toCategory(cname) {
                if(name == 'Home'){
                    this.$router.push('/');
                    return;
                }
                this.$router.push(`/index/${cname}`)
            }
        },
        mounted() {
            this.initArticle();
            window.scroll(0,0);
        },
        watch: {
            $route: {
                handler: function () {
                    window.scroll(0,0);
                    this.initArticle();
                },
            }
        }
    }
</script>


<style>

    :root {
        --side-bar-bg-color: #fff;
        --control-text-color: #777;
        --font-sans-serif: 'Ubuntu', 'Source Sans Pro', sans-serif !important;
        --font-monospace: 'Fira Code', 'Roboto Mono', monospace !important;
    }

    .articleDetail-content{
        font-family: var(--font-sans-serif);
        color: #34495e;
        -webkit-font-smoothing: antialiased;
        line-height: 1.6rem;
        letter-spacing: 0;
        margin: 0;
        overflow-x: hidden;
    }
    #write {
        max-width: 860px;
        margin: 0 auto;
        padding: 10px 10px 50px;
    }
    #write p {
        line-height: 1.6rem;
        word-spacing: .05rem;
    }

    #write ol li {
        padding-left: 0.5rem;
    }

    #write > ul:first-child,
    #write > ol:first-child {
        margin-top: 30px;
    }
    #write a {
        color: #42b983;
        font-weight: 600;
        padding: 0 2px;
        text-decoration: none;
    }
    #write
    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
        position: relative;
        margin-top: 1rem;
        margin-bottom: 1rem;
        font-weight: bold;
        line-height: 1.4;
        cursor: text;
    }
    #write h1 tt,h1 code {
        font-size: inherit !important;
    }

    #write h2 tt,h2 code {
        font-size: inherit !important;
    }

    #write h3 tt,h3 code {
        font-size: inherit !important;
    }

    #write h4 tt,h4 code {
        font-size: inherit !important;
    }

    #write h5 tt,h5 code {
        font-size: inherit !important;
    }

    #write h6 tt,h6 code {
        font-size: inherit !important;
    }

    #write h2 a,h3 a {
        color: #34495e;
    }

    #write h1 {
        padding-bottom: .4rem;
        font-size: 2.2rem;
        line-height: 1.3;
    }

    #write h2 {
        font-size: 1.75rem;
        line-height: 1.225;
        margin: 25px 0 15px;
        padding-bottom: 0.5em;
        border-bottom: 1px solid #ddd;
    }

    #write h3 {
        font-size: 1.4rem;
        line-height: 1.43;
        margin: 18px 0 7px;
    }

    #write h4 {
        font-size: 1.2rem;
    }

    #write h5 {
        font-size: 1rem;
    }

    #write h6 {
        font-size: 1rem;
        color: #777;
    }
    #write p,
    ul,
    ol,
    dl,
    table {
        margin: 0.8em 0;
    }
    #write blockquote p{
        margin: 0.3em 0;
    }
    #write li > ol,li > ul {
        margin: 0 0;
    }

    #write hr {
        height: 2px;
        padding: 0;
        margin: 16px 0;
        background-color: #e7e7e7;
        border: 0 none;
        overflow: hidden;
        box-sizing: content-box;
    }
    #write a:first-child h1,
    a:first-child h2,
    a:first-child h3,
    a:first-child h4,
    a:first-child h5,
    a:first-child h6 {
        margin-top: 0;
        padding-top: 0;
    }

    #write h1 p,
    h2 p,
    h3 p,
    h4 p,
    h5 p,
    h6 p {
        margin-top: 0;
    }
    #write li p.first {
        display: inline-block;
    }

    #write ul,
    ol {
        padding-left: 30px;
    }

    #write ul:first-child,
    ol:first-child {
        margin-top: 0;
    }

    #write ul:last-child,
    ol:last-child {
        margin-bottom: 0;
    }
    #write blockquote {
        border-left: 4px solid #42b983;
        padding: 10px 15px;
        color: #777;
        background-color: rgba(66, 185, 131, .1);
    }
    #write blockquote{
        margin: 0px;
    }
    #write table {
        padding: 0;
        word-break: initial;
    }

    #write table tr {
        border-top: 1px solid #dfe2e5;
        margin: 0;
        padding: 0;
    }

    #write table tr:nth-child(2n),
    thead {
        background-color: #fafafa;
    }

    #write table tr th {
        font-weight: bold;
        border: 1px solid #dfe2e5;
        border-bottom: 0;
        text-align: left;
        margin: 0;
        padding: 6px 13px;
    }

    #write table tr td {
        border: 1px solid #dfe2e5;
        text-align: left;
        margin: 0;
        padding: 6px 13px;
    }

    #write table tr th:first-child,
    table tr td:first-child {
        margin-top: 0;
    }

    #write table tr th:last-child,
    table tr td:last-child {
        margin-bottom: 0;
    }
    #write strong {
        padding: 0 1px;
    }

    #write em {
        padding: 0 5px 0 2px;
    }

    #write table thead th {
        background-color: #f2f2f2;
    }

    #write .CodeMirror-gutters {
        border-right: none;
    }

    #write .md-fences {
        border: 1px solid #F4F4F4;
        -webkit-font-smoothing: initial;
        margin: 0.8rem 0 !important;
        padding: 0.3rem 0 !important;
        line-height: 1.43rem;
        background-color: #F8F8F8 !important;
        border-radius: 2px;
        font-family: var(--font-monospace);
        font-size: 0.85rem;
        word-wrap: normal;
    }

    #write .CodeMirror-wrap .CodeMirror-code pre {
        padding-left: 12px;
    }
    #write pre{
        padding: 5px;
        overflow: auto;
        border: 0.5px solid lavender;
    }
    #write code, tt {
        padding: 2px 4px;
        border-radius: 2px;
        font-family: var(--font-monospace);
        font-size: 0.92rem;
        color: #e9892a;
        background-color: #f8f8f8;
    }
    #write tt {
        margin: 0 2px;
    }

    /* heighlight. */
    #write mark {
        background-color: #EBFFEB;
        border-radius: 2px;
        padding: 2px 4px;
        margin: 0 2px;
        color: #222;
        font-weight: 500;
    }

    #write del {
        padding: 1px 2px;
    }

    #write .md-task-list-item > input {
        margin-left: -1.3em;
    }

    #write pre {
        background-color: #f8f8f8;
    }


    #write img{
        border: 6px solid rgba(66, 185, 131, .1);
        border-radius: 500px;
        width: 95%;
        border-radius: 3px;
        font-family: var(--font-monospace);
        padding: 0px;
        font-size: 0.9em;
        color: inherit;
    }
    #write .hljs-tag{
        margin-left: 0px;
    }
    #write .hljs-meta,.hljs-name,.hljs-keyword,.hljs-title,.hljs-string{
        margin-left: 0px;
    }
    .head-other a {
        text-decoration: none;
        color: #7a7a7a;;
    }

    .head-other a:hover {
        color: #3273dc;
    }

    h1 {
        margin: 0;
        padding: 0;
        font-weight: 400;
    }

    .head-title {
        line-height: 40px;
        font-size: 2rem;
        height: 40px;
        width: 100%;
        color: #4B4B4B;
        margin-bottom: 10px;
    }

    .head-tags {
        line-height: 30px;
        text-align: right;
        height: 30px;
        width: 35%;
        vertical-align: top;
        display: inline-block;
    }
    .head-other i,span{
        margin-left: 10px;
    }
    .head-other {
        color: #7a7a7a;
        line-height: 30px;
        height: 30px;
        width: 60%;
        vertical-align: top;
        display: inline-block;
    }

    .articleDetail-foot {
        width: 100%;
        height: 100px;
        border: 2px solid #f0f0f0;
    }

    .articleDetail-head {
        width: 100%;
        height: 80px;
    }

    .articleDetail {
        width: 900px;
        height: auto;
        margin-left: 150px;
        min-height: 1000px;
        font-weight: 400;
        font-family: "Ubuntu", "Roboto", "Open Sans", "Microsoft YaHei", sans-serif;
    }
    .box-card .el-card__header{
        margin: 0;
        padding: 0;
        margin-bottom: 10px;
    }
    .box-card .el-card__body{
        padding: 0 20px;
    }
    .box-card{
        width: 900px;
        margin: 0px;
        padding: 20px;
    }
</style>